import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  // 设置基础路径为 /admin-static/
  base: '/admin/',
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ['vue', 'vue-router', 'pinia'],
      dts: true
    }),
    Components({
      resolvers: [ElementPlusResolver()],
      dts: true
    })
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  server: {
    port: 3100,
    host: '0.0.0.0', // 允许局域网访问
    proxy: {
      '/api': {
        // target: 'http://offgrid.vip.hnhxzkj.com:3888',
        target: 'http://192.168.0.19:3888',
        changeOrigin: true
      },
      '/uploads': {
        // target: 'http://offgrid.vip.hnhxzkj.com:3888',
        target: 'http://192.168.0.19:3888',
        changeOrigin: true
      }
    }
  },
  build: {
    outDir: 'dist',
    sourcemap: false,
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]'
      }
    }
  },
  // 生产环境配置
  preview: {
    port: 3888,
    host: true
  }
}) 